package com.party.core.service.information.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.information.InformationReadDao;
import com.party.core.dao.read.information.InformationTypeReadDao;
import com.party.core.dao.write.information.InformationTypeWriteDao;
import com.party.core.dao.write.information.InformationWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.information.Information;
import com.party.core.model.information.InformationType;
import com.party.core.service.information.IInformationService;
import com.party.core.service.information.IInformationTypeService;
import com.sun.istack.NotNull;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @ClassName InformationTypeService
 * @Description
 * @Author shenliuhai
 * @Date 2020/2/6 14:30
 **/
@Service
public class InformationTypeService implements IInformationTypeService {

    @Autowired
    private InformationTypeReadDao informationTypeReadDao;

    @Autowired
    private InformationTypeWriteDao informationTypeWriteDao;

    @Override
    public String insert(InformationType informationType) {
        BaseModel.preInsert(informationType);
        boolean result = informationTypeWriteDao.insert(informationType);
        if (result){
            return informationType.getId();
        }
        return null;

    }

    @Override
    public boolean update(InformationType informationType) {
        informationType.setUpdateDate(new Date());
        return informationTypeWriteDao.update(informationType);
    }

    @Override
    public boolean deleteLogic(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return informationTypeWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)){
            return false;
        }
        return informationTypeWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return informationTypeWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)){
            return false;
        }
        return informationTypeWriteDao.batchDelete(ids);
    }

    @Override
    public InformationType get(String id) {
        return informationTypeReadDao.get(id);
    }

    @Override
    public List<InformationType> listPage(InformationType informationType, Page page) {
        return informationTypeReadDao.listPage(informationType,page);
    }

    @Override
    public List<InformationType> list(InformationType informationType) {
        return informationTypeReadDao.listPage(informationType,null);
    }

    @Override
    public List<InformationType> batchList(@NotNull Set<String> ids, InformationType informationType, Page page) {
        if (CollectionUtils.isEmpty(ids)){
            return Collections.EMPTY_LIST;
        }
        return informationTypeReadDao.batchList(ids,new HashedMap(),page);
    }
}
